#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <syslog.h>
#include "suci.h"
#include "main.h"

int exec_cmd(char *cmd, char *val)
{
	FILE *fp;
	int ret;
	
	fp = popen(cmd, "r");
	if(val != NULL)	
		fgets(val,16,fp);	
	 ret = pclose(fp);
	
	 return ret;
}

void iptvmarkdscp(void){
	int i = 0;
	char tembuf[32] = {0}, varbuf[16] = {0}, uci_name_ex[32] = {0};
	char uci_name[32] = {0}, cmdbuf[128] = {0};
	for(i = 0;i < 10;i++){
	   sprintf(uci_name_ex,"qos.@iptvdscp[%d]",i);	
	   if(do_uci_get(uci_name_ex,tembuf) == 0){
	    memset(uci_name,0,32);
	    memset(tembuf,0,32);
	    memset(varbuf,0,16);
	    sprintf(uci_name,"%s.ip",uci_name_ex);
			do_uci_get(uci_name,tembuf);
			sprintf(uci_name,"%s.dscp",uci_name_ex);
			do_uci_get(uci_name,varbuf);
			sprintf(cmdbuf,"%s %s %s %s",EBTS2,tembuf,TARGET,varbuf);
	    exec_cmd(cmdbuf,NULL);	 
	  }
	  else break;
	
	}
}

void ipmark(void){
	int i = 0;
	char tembuf[16] = {0}, varbuf[16] = {0}, tmpbuf[32] = {0}, uci_name_ex[32] = {0};
	char uci_name[32] = {0}, cmdbuf[128] = {0}, markbuf[16] = {0};
	for(i = 0;;i++){
	   sprintf(uci_name_ex,"qos.@umark[%d]",i);	
	   if(do_uci_get(uci_name_ex,tembuf) == 0){
	    memset(uci_name,0,32);
	    memset(tembuf,0,16);
	    memset(tmpbuf,0,32);
	    memset(varbuf,0,16);
	    memset(markbuf,0,16);
	    sprintf(uci_name,"%s.protocol",uci_name_ex);
			do_uci_get(uci_name,tembuf);
			sprintf(uci_name,"%s.firstPort",uci_name_ex);
			do_uci_get(uci_name,varbuf);
			sprintf(uci_name,"%s.lastPort",uci_name_ex);
			if(do_uci_get(uci_name,tmpbuf) == 0){
				strcat(varbuf,":");
				strcat(varbuf,tmpbuf);
			  }
			sprintf(uci_name,"%s.setmark",uci_name_ex);
			do_uci_get(uci_name,markbuf);
			sprintf(cmdbuf,"%s %s -o eth0 -m multiport --dports %s -j MARK --set-mark %s",IPTS3,tembuf,varbuf,markbuf);
	    exec_cmd(cmdbuf,NULL);	 
	  }
	  else break;
	}	
	for(i = 0;;i++){
	   sprintf(uci_name_ex,"qos.@device[%d]",i);	
	   if(do_uci_get(uci_name_ex,tembuf) == 0){
	    memset(uci_name,0,32);
	    memset(varbuf,0,16);
	    memset(tmpbuf,0,32);
	    sprintf(uci_name,"%s.mac",uci_name_ex);
			do_uci_get(uci_name,tmpbuf);
			sprintf(uci_name,"%s.setmark",uci_name_ex);
			do_uci_get(uci_name,varbuf);
			sprintf(cmdbuf,"iptables -t mangle -A macmark -m mac --mac-source %s -j MARK --set-mark %s",tmpbuf,varbuf);
	    exec_cmd(cmdbuf,NULL);	 
	  }
	  else break;
	}	
	
	
}

void ssidmarkdscp(void){
	int i = 0;
	char tembuf[16] = {0}, varbuf[16] = {0}, uci_name_ex[32] = {0};
	char uci_name[32] = {0}, cmdbuf[128] = {0};
	for(i = 0;i < 10;i++){
	   sprintf(uci_name_ex,"qos.@markdscp[%d]",i);	
	   if(do_uci_get(uci_name_ex,tembuf) == 0){
	    memset(uci_name,0,32);
	    memset(tembuf,0,16);
	    memset(varbuf,0,16);
	    sprintf(uci_name,"%s.ifname",uci_name_ex);
			do_uci_get(uci_name,tembuf);
			sprintf(uci_name,"%s.dscp",uci_name_ex);
			do_uci_get(uci_name,varbuf);
			sprintf(cmdbuf,"%s -o %s %s %s --mark-target CONTINUE",EBTS1,tembuf,TARGET,varbuf);
	    exec_cmd(cmdbuf,NULL);	 
	  }
	  else break;
	}
}

long int getLocalTimeWithSeconds()
{
	time_t timep;
	struct tm *p;

	time(&timep);
	printf("time() : %ld \n", timep);
	p = localtime(&timep);
	timep = mktime(p);
	printf("time()->localtime()->mktime():%ld\n", timep);

	return (long int)timep;
}

int getvalue_mapfile_byinstance(char* filename,char *value, int inst)
{
    int i = 0;
	int instance;
	char szinstance[16];
	char szvalue[256];
	
	FILE *fp = fopen(filename,"r");
	if (fp)
	{
		while(!feof(fp))
		{
			fscanf(fp,"%s %*s %s",szinstance,szvalue);
			instance	= atoi(szinstance);
			if (instance == inst)
			{
				printf("value = %s \n", szvalue);
				strcpy(value,szvalue);
				fclose(fp);
				return 0;
			}
			i++;
		}
		fclose(fp);
	}
	return -1;
}


/*void ssidmarkdscp(void){
	int i = 0;
	char tembuf[16] = {0}, varbuf[16] = {0}, uci_name_ex[32] = {0};
	char uci_name[32] = {0}, cmdbuf[128] = {0};
	for(i = 0;i < 10;i++){
	   sprintf(uci_name_ex,"qos.@markdscp[%d]",i);	
	   if(do_uci_get(uci_name_ex,tembuf) == 0){
	    memset(uci_name,0,32);
	    memset(tembuf,0,16);
	    memset(varbuf,0,16);
	    sprintf(uci_name,"%s.ifname",uci_name_ex);
			do_uci_get(uci_name,tembuf);
			sprintf(uci_name,"%s.dscp",uci_name_ex);
			do_uci_get(uci_name,varbuf);
			sprintf(cmdbuf,"%s -o %s %s %s --mark-target CONTINUE",EBTS1,tembuf,TARGET,varbuf);
	    exec_cmd(cmdbuf,NULL);	 
	  }
	  else break;
	}
}
*/

#if 0
void test_uci()
{
        int i;
        int ret=0;
	/*
	 *root@rt4230w:/etc/config# uci show coral_config 
	 coral_config.@fir[0]=fir
	 coral_config.@fir[0].connection_type='0'
	 coral_config.@fir[0].lifetime='86400'
	 coral_config.@fir[0].enable='0'
	 coral_config.@fir[0].status='Disabled'
	 coral_config.@sec[0]=sec
	 coral_config.@sec[0].wan_ipv6addres_orgin='DHCPv6'
	 coral_config.@sec[0].ipv4anycast_relay='192.88.99.1'
	 coral_config.@thr[0]=thr
	 coral_config.@thr[0].enable='0'
	 coral_config.@thr[0].userclass='charter_map'
	 *
	 */
	 char value[8] = {0} , tmpbuf[16] = {0} , uci_name[64] = {0};
	 for(i=1;ret <80;i++)
         {
         memset(uci_name,0,64);
	   memset(value,0,8);
	   memset(tmpbuf,0,8);
         sprintf(uci_name,"coral_config.@fir[%d]",i); 
         do_uci_get(uci_name, value);
         printf("test_uci=%s\n",uci_name);
         }
}
#endif

//uci_tmp_config_name  queue_template.template
int add_template_node(int index,char *uci_tmp_config_name, char *created_qos_name)
{
        int ret_rename=0;
        int ret_commit=0;
        char file_input[64]={0};//file :exp:  /etc/config/queue_template
        char file_output[64]={0};//file: exp: /etc/config/queue
	
        char old_config_name[32]={0};//name: exp   : queue_template
        char old_config_path[32]={0};//queue_template.template
        char new2old_config_path[32]={0};//name:exp :queue_template.Device_QoS_Queue_%d
        char new_config_name[32]={0};//name:exp :queue   not used
      
        char old_section_name[32]={0};//name: exp:  template
        char new_section_name[32]={0};//name: exp:  Device_QoS_Queue_%d

        memset (file_input,0,sizeof(file_input));
        memset (file_output,0,sizeof(file_output));
        
        memset (old_config_name,0,sizeof(old_config_name));
        memset (new2old_config_path,0,sizeof(new2old_config_path)); 
        memset (new_config_name,0,sizeof(new_config_name));
    
        memset (old_section_name,0,sizeof(old_section_name));
        memset (new_section_name,0,sizeof(new_section_name));

        //old section name
        sprintf(old_section_name,"template");

        //new section name
        if(strcmp(uci_tmp_config_name, "queue_template") == 0)
                sprintf(new_section_name,"Device_QoS_Queue_%d",index);
        if(strcmp(uci_tmp_config_name, "classification_template") == 0)
                sprintf(new_section_name,"Device_QoS_Classification_%d",index);

        //old_config_name for commit uci config
        sprintf(old_config_name,uci_tmp_config_name);

        printf("1 old_section_name= %s\n",old_section_name);
        printf("1 new_section_name= %s\n",new_section_name);

        //old config modify section name       
        sprintf(old_config_path,"%s.template",uci_tmp_config_name);//queue_template+template
        printf("2 old_config_path = %s\n",old_config_path);
    
        //modify old_config_path section name to Device_QoS_Queue_%d
        ret_rename = do_uci_rename(old_config_path, new_section_name);
        //commit the modify section name to file
        ret_commit = do_uci_commit(old_config_name);
        printf("3  [ret_rename=%d]  [ret_commit=%d]\n", ret_rename,ret_commit);
	
        //copy template node for creat new uci file(queue ,  classifcation)
        if(ret_rename==0 && ret_commit==0)
        {
            FILE *fi,*fo;
                char c;
                sprintf(file_input, "%s%s",TABLE_PATH,uci_tmp_config_name);
                sprintf(file_output, "%s%s",TABLE_PATH,created_qos_name);
                printf("TABLE_PATH=%s\n",TABLE_PATH);
                printf("TABLE_PATH+file_input=%s\n",file_input);
                printf("%s\n",file_input);
                printf("TABLE_PATH+file_output=%s\n",file_output);
                
                fi=fopen(file_input,"r");
                fo=fopen(file_output,"ab");
                while(fscanf(fi,"%c",&c)!=EOF)
                    fprintf(fo,"%c",c);
                        fclose(fi);
                        fclose(fo);
                        printf("Created Success!\n");
        }else
        {
            printf("Created Fail!\n");
                return -1;
        }
        //modify section name
        
        sprintf(new2old_config_path,"%s.%s",old_config_name,new_section_name);
        printf("4 new2old_config_path=%s\n",new2old_config_path);
            
        ret_rename = do_uci_rename(new2old_config_path,old_section_name);
        //sava the modify section name to file
        ret_commit = do_uci_commit(old_config_name);

        if(ret_rename==0 && ret_commit==0)
        {
                printf("5 Reset Success!\n ");
                return 0;
        }else
        {
                printf("5 Reset Fail  [ret_rename=%d]  [ret_commit=%d]\n", ret_rename,ret_commit);
                printf("5 Reset Fail!\n ");
                return -1;
        }
}

#if 0
int creat_classification_rules()
{
	char Enable[32] = {0};
	char Order[32] = {0};
	char AllInterfaces[32] = {0};
	char DestIP[32] = {0};
	char DestMask[32] = {0};
	char DestIPExclude[32] = {0};
	char SourceIP[32] = {0};
	char SourceMask[32] = {0};
	char SourceIPExclude[32] = {0};
	char DestPort[32] = {0};
	char DestPortRangeMax[32] = {0};
	char DestPortExclude[32] = {0};
	char SourcePort[32] = {0};
	char SourcePortRangeMax[32] = {0};
	char SourcePortExclude[32] = {0};
	char SourceMACAddress[32] = {0};
	char SourceMACMask[32] = {0};
	char SourceMACExclude[32] = {0};
	char DestMACAddress[32] = {0};
	char DestMACMask[32] = {0};
	char DestMACExclude[32] = {0};
	char TCPACK[32] = {0};
	char TCPACKExclude[32] = {0};
	char DSCPMark[32] = {0};
	char TrafficClass[32] = {0};
	char Protocol[32] = {0};
	char ProtocolExclude[32] = {0};
	char Ethertype[32] = {0};
	char EthertypeExclude[32] = {0};
	char SSAP[32] = {0};
	char SSAPExclude[32] = {0};
	char DSCPCheck[32] = {0};
	char DSCPExclude[32] = {0};
	char EthernetPriorityCheck[32] = {0};
	char EthernetPriorityExclude[32] = {0};
	char VLANIDCheck[32] = {0};
	char VLANIDExclude[32] = {0};
	char IPLengthMin[32] = {0};
	char IPLengthMax[32] = {0};
	char IPLengthExclude[32] = {0};
	char App[32] = {0};
	char iptablescommand[1024] = {0};
	char ebtablescommand[1024] = {0};

	memset(ClassificationNumberOfEntries, 0, sizeof(ClassificationNumberOfEntries));
	do_uci_get("trconf.Device_QoS.ClassificationNumberOfEntries", ClassificationNumberOfEntries);
	printf("ClassificationNumberOfEntries: %s\n", ClassificationNumberOfEntries);

	i = 0;
	j = 0;
	while(i < atoi(ClassificationNumberOfEntries))
	{
		j++;
		sprintf(name, "trconf.Device_QoS_Classification_%d", j);
		memset(value, 0, sizeof(value));
		do_uci_get(name,value);
		if(strcmp(value, "acs") == 0)
		{
			i++;
			memset(Enable, 0, sizeof(Enable));
			sprintf(name, "trconf.Device_QoS_Classification_%d.Enable", j);	
			do_uci_get(name, Enable);

			if(atoi(Enable) == 0)
			{
				continue;
			}
			
			memset(Order, 0, sizeof(Order));
			memset(Interface, 0, sizeof(Interface));
			memset(AllInterfaces, 0, sizeof(AllInterfaces));
			memset(DestIP, 0, sizeof(DestIP));
			memset(DestMask, 0, sizeof(DestMask));
			memset(DestIPExclude, 0, sizeof(DestIPExclude));
			memset(SourceIP, 0, sizeof(SourceIP));
			memset(SourceMask, 0, sizeof(SourceMask));
			memset(SourceIPExclude, 0, sizeof(SourceIPExclude));
			memset(DestPort, 0, sizeof(DestPort));
			memset(DestPortRangeMax, 0, sizeof(DestPortRangeMax));
			memset(DestPortExclude, 0, sizeof(DestPortExclude));
			memset(SourcePort, 0, sizeof(SourcePort));
			memset(SourcePortRangeMax, 0, sizeof(SourcePortRangeMax));
			memset(SourcePortExclude, 0, sizeof(SourcePortExclude));
			memset(SourceMACAddress, 0, sizeof(SourceMACAddress));
			memset(SourceMACMask, 0, sizeof(SourceMACMask));
			memset(SourceMACExclude, 0, sizeof(SourceMACExclude));
			memset(DestMACAddress, 0, sizeof(DestMACAddress));
			memset(DestMACMask, 0, sizeof(DestMACMask));
			memset(DestMACExclude, 0, sizeof(DestMACExclude));
			memset(TCPACK, 0, sizeof(TCPACK));
			memset(TCPACKExclude, 0, sizeof(TCPACKExclude));
			memset(DSCPMark, 0, sizeof(DSCPMark));
			memset(Protocol, 0, sizeof(Protocol));
			memset(ProtocolExclude, 0, sizeof(ProtocolExclude));
			memset(TrafficClass, 0, sizeof(TrafficClass));
			memset(Ethertype, 0, sizeof(Ethertype));
			memset(EthertypeExclude, 0, sizeof(EthertypeExclude));
			memset(SSAP, 0, sizeof(SSAP));
			memset(SSAPExclude, 0, sizeof(SSAPExclude));
			memset(DSCPCheck, 0, sizeof(DSCPCheck));
			memset(DSCPExclude, 0, sizeof(DSCPExclude));
			memset(EthernetPriorityCheck, 0, sizeof(EthernetPriorityCheck));
			memset(EthernetPriorityExclude, 0, sizeof(EthernetPriorityExclude));
			memset(VLANIDCheck, 0, sizeof(VLANIDCheck));
			memset(VLANIDExclude, 0, sizeof(VLANIDExclude));
			memset(App, 0, sizeof(App));
			memset(IPLengthMin, 0, sizeof(IPLengthMin));
			memset(IPLengthMax, 0, sizeof(IPLengthMax));
			memset(IPLengthExclude, 0, sizeof(IPLengthExclude));
			
			sprintf(name, "trconf.Device_QoS_Classification_%d.Order", j);	
			do_uci_get(name, Order);
			sprintf(name, "trconf.Device_QoS_Classification_%d.Interface", j);	
			do_uci_get(name, Interface);
			sprintf(name, "trconf.Device_QoS_Classification_%d.AllInterfaces", j);	
			do_uci_get(name, AllInterfaces);
			sprintf(name, "trconf.Device_QoS_Classification_%d.DestIP", j);	
			do_uci_get(name, DestIP);
			sprintf(name, "trconf.Device_QoS_Classification_%d.DestMask", j);	
			do_uci_get(name, DestMask);
			sprintf(name, "trconf.Device_QoS_Classification_%d.DestIPExclude", j);	
			do_uci_get(name, DestIPExclude);
			sprintf(name, "trconf.Device_QoS_Classification_%d.SourceIP", j);	
			do_uci_get(name, SourceIP);
			sprintf(name, "trconf.Device_QoS_Classification_%d.SourceMask", j);	
			do_uci_get(name, SourceMask);
			sprintf(name, "trconf.Device_QoS_Classification_%d.SourceIPExclude", j);	
			do_uci_get(name, SourceIPExclude);
			sprintf(name, "trconf.Device_QoS_Classification_%d.DestPort", j);	
			do_uci_get(name, DestPort);
			sprintf(name, "trconf.Device_QoS_Classification_%d.DestPortRangeMax", j);	
			do_uci_get(name, DestPortRangeMax);
			sprintf(name, "trconf.Device_QoS_Classification_%d.DestPortExclude", j);	
			do_uci_get(name, DestPortExclude);
			sprintf(name, "trconf.Device_QoS_Classification_%d.SourcePort", j);	
			do_uci_get(name, SourcePort);
			sprintf(name, "trconf.Device_QoS_Classification_%d.SourcePortRangeMax", j);	
			do_uci_get(name, SourcePortRangeMax);
			sprintf(name, "trconf.Device_QoS_Classification_%d.SourcePortExclude", j);	
			do_uci_get(name, SourcePortExclude);
			sprintf(name, "trconf.Device_QoS_Classification_%d.SourceMACAddress", j);	
			do_uci_get(name, SourceMACAddress);
			sprintf(name, "trconf.Device_QoS_Classification_%d.SourceMACMask", j);	
			do_uci_get(name, SourceMACMask);
			sprintf(name, "trconf.Device_QoS_Classification_%d.SourceMACExclude", j);	
			do_uci_get(name, SourceMACExclude);
			sprintf(name, "trconf.Device_QoS_Classification_%d.TCPACK", j);	
			do_uci_get(name, TCPACK);
			sprintf(name, "trconf.Device_QoS_Classification_%d.TCPACKExclude", j);	
			do_uci_get(name, TCPACKExclude);
			sprintf(name, "trconf.Device_QoS_Classification_%d.TrafficClass", j);	
			do_uci_get(name, TrafficClass);
			sprintf(name, "trconf.Device_QoS_Classification_%d.DSCPMark", j);	
			do_uci_get(name, DSCPMark);
			sprintf(name, "trconf.Device_QoS_Classification_%d.Protocol", j);	
			do_uci_get(name, Protocol);
			sprintf(name, "trconf.Device_QoS_Classification_%d.ProtocolExclude", j);	
			do_uci_get(name, ProtocolExclude);
			sprintf(name, "trconf.Device_QoS_Classification_%d.DestMACAddress", j);	
			do_uci_get(name, DestMACAddress);
			sprintf(name, "trconf.Device_QoS_Classification_%d.DestMACMask", j);	
			do_uci_get(name, DestMACMask);
			sprintf(name, "trconf.Device_QoS_Classification_%d.DestMACExclude", j);	
			do_uci_get(name, DestMACExclude);
			sprintf(name, "trconf.Device_QoS_Classification_%d.Ethertype", j);	
			do_uci_get(name, Ethertype);
			sprintf(name, "trconf.Device_QoS_Classification_%d.EthertypeExclude", j);	
			do_uci_get(name, EthertypeExclude);
			sprintf(name, "trconf.Device_QoS_Classification_%d.SSAP", j);	
			do_uci_get(name, SSAP);
			sprintf(name, "trconf.Device_QoS_Classification_%d.SSAPExclude", j);	
			do_uci_get(name, SSAPExclude);
			sprintf(name, "trconf.Device_QoS_Classification_%d.DSCPCheck", j);	
			do_uci_get(name, DSCPCheck);
			sprintf(name, "trconf.Device_QoS_Classification_%d.DSCPExclude", j);	
			do_uci_get(name, DSCPExclude);
			sprintf(name, "trconf.Device_QoS_Classification_%d.EthernetPriorityCheck", j);	
			do_uci_get(name, EthernetPriorityCheck);
			sprintf(name, "trconf.Device_QoS_Classification_%d.EthernetPriorityExclude", j);	
			do_uci_get(name, EthernetPriorityExclude);
			sprintf(name, "trconf.Device_QoS_Classification_%d.VLANIDCheck", j);	
			do_uci_get(name, VLANIDCheck);
			sprintf(name, "trconf.Device_QoS_Classification_%d.VLANIDExclude", j);	
			do_uci_get(name, VLANIDExclude);
			sprintf(name, "trconf.Device_QoS_Classification_%d.App", j);	
			do_uci_get(name, App);
			sprintf(name, "trconf.Device_QoS_Classification_%d.IPLengthMin", j);	
			do_uci_get(name, IPLengthMin);
			sprintf(name, "trconf.Device_QoS_Classification_%d.IPLengthMax", j);	
			do_uci_get(name, IPLengthMax);
			sprintf(name, "trconf.Device_QoS_Classification_%d.IPLengthExclude", j);	
			do_uci_get(name, IPLengthExclude);

			char markmatch[64] = {0};
			if(Order[0] != '\0')
			{
				sprintf(markmatch, "-m mark --mark %s", Order);
			}

			char intefacematch[64] = {0};
			memset(intefacematch, 0, sizeof(intefacematch));
			if(atoi(AllInterfaces) != 1)
			{
				if(strcmp(Interface, "Device.IP.Interface.1") == 0)
				{
					strcpy(intefacematch, "-i br-lan");
				}
				else if(strcmp(Interface, "Device.IP.Interface.2") == 0)
				{
					strcpy(intefacematch, "-i eth0");
				}
			}
			
			char destipmatch[64] = {0};
			if(atoi(DestIPExclude) == 1)
			{
				if((DestIP[0] != '\0') && (DestMask[0] == '\0'))
					sprintf(destipmatch, "! -d %s", DestIP);
				if((DestIP[0] != '\0') && (DestMask[0] != '\0'))
					sprintf(destipmatch, "! -d %s/%s", DestIP, DestMask);
			}
			else
			{
				if((DestIP[0] != '\0') && (DestMask[0] == '\0'))
					sprintf(destipmatch, "-d %s", DestIP);
				if((DestIP[0] != '\0') && (DestMask[0] != '\0'))
					sprintf(destipmatch, "-d %s/%s", DestIP, DestMask);
			}
				
			char srcipmatch[64] = {0};
			if(atoi(SourceIPExclude) == 1)
			{
				if((SourceIP[0] != '\0') && (SourceMask[0] == '\0'))
					sprintf(srcipmatch, "! -s %s", SourceIP);
				if((SourceIP[0] != '\0') && (SourceMask[0] != '\0'))
					sprintf(srcipmatch, "! -s %s/%s", SourceIP, SourceMask);
			}
			else
			{
				if((SourceIP[0] != '\0') && (SourceMask[0] == '\0'))
					sprintf(srcipmatch, "-s %s", SourceIP);
				if((SourceIP[0] != '\0') && (SourceMask[0] != '\0'))
					sprintf(srcipmatch, "-s %s/%s", SourceIP, SourceMask);
			}

			char Protocolmatch[64] = {0};
			if(atoi(ProtocolExclude) == 1)
			{
				if((Protocol[0] != '\0') && (atoi(Protocol) != -1))
					sprintf(Protocolmatch, "! -p %s", Protocol);
			}
			else
			{
				if((Protocol[0] != '\0') && (atoi(Protocol) != -1))
					sprintf(Protocolmatch, "-p %s", Protocol);
			}

			char destportmatch[64] = {0};
			if(atoi(DestPortExclude) == 1)
			{
				if((DestPort[0] != '\0') && (DestPortRangeMax[0] == '\0'))
					sprintf(destportmatch, "! --dport %s", DestPort);
				if((DestPort[0] != '\0') && (DestPortRangeMax[0] != '\0'))
					sprintf(destportmatch, "! --dport %s:%s", DestPort, DestPortRangeMax);
				if(DestPort[0] != '\0')
					strcpy(Protocolmatch, "-p tcp");
			}
			else
			{
				if((DestPort[0] != '\0') && (DestPortRangeMax[0] == '\0'))
					sprintf(destportmatch, "--dport %s", DestPort);
				if((DestPort[0] != '\0') && (DestPortRangeMax[0] != '\0'))
					sprintf(destportmatch, "--dport %s:%s", DestPort, DestPortRangeMax);
				if(DestPort[0] != '\0')
					strcpy(Protocolmatch, "-p tcp");
			}
			
			char srcportmatch[64] = {0};
			if(atoi(SourcePortExclude) == 1)
			{
				if((SourcePort[0] != '\0') && (SourcePortRangeMax[0] == '\0'))
					sprintf(srcportmatch, "! --sport %s", SourcePort);
				if((SourcePort[0] != '\0') && (SourcePortRangeMax[0] != '\0'))
					sprintf(srcportmatch, "! --sport %s:%s", SourcePort, SourcePortRangeMax);
				if(SourcePort[0] != '\0')
					strcpy(Protocolmatch, "-p tcp");
			}
			else
			{
				if((SourcePort[0] != '\0') && (SourcePortRangeMax[0] == '\0'))
					sprintf(srcportmatch, "--sport %s", SourcePort);
				if((SourcePort[0] != '\0') && (SourcePortRangeMax[0] != '\0'))
					sprintf(srcportmatch, "--sport %s:%s", SourcePort, SourcePortRangeMax);
				if(SourcePort[0] != '\0')
					strcpy(Protocolmatch, "-p tcp");
			}
			
			char srcmacmatch[64] = {0};
			memset(srcmacmatch, 0, sizeof(srcmacmatch));
			if(atoi(SourceMACExclude) == 1)
			{
				if((SourceMACAddress[0] != '\0') && (SourceMACMask[0] == '\0'))
					sprintf(srcmacmatch, "-s ! %s", SourceMACAddress);
				if((SourceMACAddress[0] != '\0') && (SourceMACMask[0] != '\0'))
					sprintf(srcmacmatch, "-s ! %s/%s", SourceMACAddress, SourceMACMask);
			}
			else
			{
				if((SourceMACAddress[0] != '\0') && (SourceMACMask[0] == '\0'))
					sprintf(srcmacmatch, "-s %s", SourceMACAddress);
				if((SourceMACAddress[0] != '\0') && (SourceMACMask[0] != '\0'))
					sprintf(srcmacmatch, "-s %s/%s", SourceMACAddress, SourceMACMask);
			}

			char destmacmatch[64] = {0};
			memset(destmacmatch, 0, sizeof(destmacmatch));
			if(atoi(DestMACExclude) == 1)
			{
				if((DestMACAddress[0] != '\0') && (DestMACMask[0] == '\0'))
					sprintf(destmacmatch, "-d ! %s", DestMACAddress);
				if((DestMACAddress[0] != '\0') && (DestMACMask[0] != '\0'))
					sprintf(destmacmatch, "-d ! %s/%s", DestMACAddress, DestMACMask);
			}
			else
			{
				if((DestMACAddress[0] != '\0') && (DestMACMask[0] == '\0'))
					sprintf(destmacmatch, "-d %s", DestMACAddress);
				if((DestMACAddress[0] != '\0') && (DestMACMask[0] != '\0'))
					sprintf(destmacmatch, "-d %s/%s", DestMACAddress, DestMACMask);
			}

			char ethertypematch[64] = {0};
			memset(ethertypematch, 0, sizeof(ethertypematch));
			if(atoi(EthertypeExclude) == 1)
			{
				if((Ethertype[0] != '\0') && (atoi(Ethertype) != -1))
					sprintf(ethertypematch, "-p ! %s", Ethertype);
			}
			else
			{
				if((Ethertype[0] != '\0') && (atoi(Ethertype) != -1))
					sprintf(ethertypematch, "-p %s", Ethertype);
			}

			char sapmatch[64] = {0};
			memset(sapmatch, 0, sizeof(sapmatch));
			if(atoi(SSAPExclude) == 1)
			{
				if((SSAP[0] != '\0') && (atoi(SSAP) != -1))
				{
					strcpy(ethertypematch, "-p LENGTH");
					sprintf(sapmatch, "--802_3-sap ! %s", SSAP);
				}
			}
			else
			{
				if((SSAP[0] != '\0') && (atoi(SSAP) != -1))
				{
					strcpy(ethertypematch, "-p LENGTH");
					sprintf(sapmatch, "--802_3-sap %s", SSAP);
				}
			}
					
			char tcpackmatch[64] = {0};
			if(atoi(TCPACKExclude) == 1)
			{
				if(atoi(TCPACK) == 1)
				{
					sprintf(tcpackmatch, "! --tcp-flags ALL ACK");
					strcpy(Protocolmatch, "-p tcp");
				}
			}
			else
			{
				if(atoi(TCPACK) == 1)
				{
					sprintf(tcpackmatch, "--tcp-flags ALL ACK");
					strcpy(Protocolmatch, "-p tcp");
				}
			}

			char dscpmatch[64] = {0};
			if(atoi(DSCPExclude) == 1)
			{
				if((DSCPCheck[0] != '\0') && (atoi(DSCPCheck) != -1))
					sprintf(dscpmatch, "-m dscp ! --dscp %s", DSCPCheck);
			}
			else
			{
				if((DSCPCheck[0] != '\0') && (atoi(DSCPCheck) != -1))
					sprintf(dscpmatch, "-m dscp --dscp %s", DSCPCheck);
			}

			char etherpriomatch[64] = {0};
			memset(etherpriomatch, 0, sizeof(etherpriomatch));
			if(atoi(EthernetPriorityExclude) == 1)
			{
				if((EthernetPriorityCheck[0] != '\0') && (atoi(EthernetPriorityCheck) != -1))
				{
					strcpy(ethertypematch, "-p 0x8100");
					sprintf(etherpriomatch, "-vlan-prio ! %s", EthernetPriorityCheck);
					memset(sapmatch, 0, sizeof(sapmatch));
				}
			}
			else
			{
				if((EthernetPriorityCheck[0] != '\0') && (atoi(EthernetPriorityCheck) != -1))
				{
					strcpy(ethertypematch, "-p 0x8100");
					sprintf(etherpriomatch, "-vlan-prio %s", EthernetPriorityCheck);
					memset(sapmatch, 0, sizeof(sapmatch));
				}
			}

			char vlanidmatch[64] = {0};
			memset(vlanidmatch, 0, sizeof(vlanidmatch));
			if(atoi(VLANIDExclude) == 1)
			{
				if((VLANIDCheck[0] != '\0') && (atoi(VLANIDCheck) != -1))
				{
					strcpy(ethertypematch, "-p 0x8100");
					sprintf(vlanidmatch, "--vlan-id ! %s", VLANIDCheck);
					memset(sapmatch, 0, sizeof(sapmatch));
				}
			}
			else
			{
				if((VLANIDCheck[0] != '\0') && (atoi(VLANIDCheck) != -1))
				{
					strcpy(ethertypematch, "-p 0x8100");
					sprintf(vlanidmatch, "--vlan-id %s", VLANIDCheck);
					memset(sapmatch, 0, sizeof(sapmatch));
				}
			}

			char iplengthmatch[64] = {0};
			if(atoi(IPLengthExclude) == 1)
			{
				if((IPLengthMin[0] != '\0') && (IPLengthMax[0] == '\0'))
					sprintf(iplengthmatch, "-m length ! --length  %s", IPLengthMin);
				if((IPLengthMin[0] != '\0') && (IPLengthMax[0] != '\0'))
					sprintf(iplengthmatch, "-m length ! --length  %s:%s", IPLengthMin, IPLengthMax);
			}
			else
			{
				if((IPLengthMin[0] != '\0') && (IPLengthMax[0] == '\0'))
					sprintf(iplengthmatch, "-m length --length %s", IPLengthMin);
				if((IPLengthMin[0] != '\0') && (IPLengthMax[0] != '\0'))
					sprintf(iplengthmatch, "-m length --length %s:%s", IPLengthMin, IPLengthMax);
			}
			
			if(atoi(TrafficClass) < 0)
			{
				char *index = strrchr(App, '.');
				char Alias[256] = {0};
				char name[256] = {0};
				char ProtocolIdentifier[256] = {0};
				char DefaultTrafficClass[256] = {0};
				char DefaultDSCPMark[256] = {0};
				char *p = NULL;
				
				if (index != NULL)
				{
					getvalue_mapfile_byinstance("/oneagent/conf/QoSAppMap.mapping", Alias, atoi(index+1));
					p = strchr(Alias, '_');
					if(p != NULL)
					{
						sprintf(name, "trconf.Device_QoS_App_%d.ProtocolIdentifier", atoi(p+1));		
						printf("name[%s]\n", name);
						do_uci_get(name, ProtocolIdentifier);
						printf("value[%s]\n", ProtocolIdentifier);
						if(strcasestr(ProtocolIdentifier, "sip") != NULL)
						{
							strcpy(destportmatch, "--dport 6060");
							strcpy(Protocolmatch, "-p tcp");
						}
						else if(strcasestr(ProtocolIdentifier, "h.323") != NULL)
						{
							strcpy(destportmatch, "--dport 1720");
							strcpy(Protocolmatch, "-p tcp");
						}
						else if(strcasestr(ProtocolIdentifier, "h.248") != NULL)
						{
							strcpy(destportmatch, "--dport 2944");
							strcpy(Protocolmatch, "-p tcp");
						}
						else if(strcasestr(ProtocolIdentifier, "mgcp") != NULL)
						{
							strcpy(destportmatch, "--dport 2727");
							strcpy(Protocolmatch, "-p tcp");
						}
						sprintf(name, "trconf.Device_QoS_App_%d.DefaultTrafficClass", atoi(p+1));		
						do_uci_get(name, DefaultTrafficClass);
						printf("name[%s]\n", name);
						printf("value[%s]\n", DefaultTrafficClass);
						sprintf(name, "trconf.Device_QoS_App_%d.DefaultDSCPMark", atoi(p+1));		
						do_uci_get(name, DefaultDSCPMark);
						printf("name[%s]\n", name);
						printf("value[%s]\n", DefaultDSCPMark);
						strcpy(TrafficClass, DefaultTrafficClass);
						strcpy(DSCPMark, DefaultDSCPMark);
					}
				}
			}

			if(strcmp(cmd, "start") == 0)
			{
				if((srcmacmatch[0] != '\0') || (destmacmatch[0] != '\0') || (ethertypematch[0] != '\0') || (sapmatch[0] != '\0') || (vlanidmatch[0] != '\0') || (etherpriomatch[0] != '\0'))
				{
					sprintf(ebtablescommand, "ebtables -A FORWARD %s %s %s %s %s %s -j mark --mark-set %s", ethertypematch, 
						srcmacmatch, destmacmatch, sapmatch, vlanidmatch, etherpriomatch, Order);	
					printf("ebtablescommand: %s\n", ebtablescommand);
					system(ebtablescommand);
					sprintf(iptablescommand, "iptables -t mangle -A FORWARD %s %s %s %s %s %s %s %s %s %s -j CLASSIFY --set-class %s:0", intefacematch, destipmatch, srcipmatch, Protocolmatch,
							destportmatch, srcportmatch, tcpackmatch, dscpmatch, markmatch, iplengthmatch, TrafficClass);
					printf("iptablescommand: %s\n", iptablescommand);
					system(iptablescommand);
					sprintf(iptablescommand, "iptables -t mangle -A FORWARD %s %s %s %s %s %s %s %s %s %s -j DSCP --set-dscp %s", intefacematch, destipmatch, srcipmatch, Protocolmatch,
							destportmatch, srcportmatch, tcpackmatch, dscpmatch, markmatch, iplengthmatch, DSCPMark);
					printf("iptablescommand: %s\n", iptablescommand);
					system(iptablescommand);
				}
				else
				{
					sprintf(iptablescommand, "iptables -t mangle -A FORWARD %s %s %s %s %s %s %s %s %s -j CLASSIFY --set-class %s:0", intefacematch, destipmatch, srcipmatch, Protocolmatch,
							destportmatch, srcportmatch, tcpackmatch, dscpmatch, iplengthmatch, TrafficClass);
					printf("iptablescommand: %s\n", iptablescommand);
					system(iptablescommand);
					sprintf(iptablescommand, "iptables -t mangle -A FORWARD %s %s %s %s %s %s %s %s %s -j DSCP --set-dscp %s", intefacematch, destipmatch, srcipmatch, Protocolmatch,
							destportmatch, srcportmatch, tcpackmatch, dscpmatch, iplengthmatch, DSCPMark);
					printf("iptablescommand: %s\n", iptablescommand);
					system(iptablescommand);
				}
			}
			else
			{
				if((srcmacmatch[0] != '\0') || (destmacmatch[0] != '\0') || (ethertypematch[0] != '\0') || (sapmatch[0] != '\0') || (vlanidmatch[0] != '\0') || (etherpriomatch[0] != '\0'))
				{
					sprintf(ebtablescommand, "ebtables -D FORWARD %s %s %s %s %s %s -j mark --mark-set %s", ethertypematch, 
						srcmacmatch, destmacmatch, sapmatch, vlanidmatch, etherpriomatch, Order);	
					printf("ebtablescommand: %s\n", ebtablescommand);
					system(ebtablescommand);
					sprintf(iptablescommand, "iptables -t mangle -D FORWARD %s %s %s %s %s %s %s %s %s %s -j CLASSIFY --set-class %s:0", intefacematch, destipmatch, srcipmatch, Protocolmatch,
							destportmatch, srcportmatch, tcpackmatch, dscpmatch, markmatch, iplengthmatch, TrafficClass);
					printf("iptablescommand: %s\n", iptablescommand);
					system(iptablescommand);
					sprintf(iptablescommand, "iptables -t mangle -D FORWARD %s %s %s %s %s %s %s %s %s %s -j DSCP --set-dscp %s", intefacematch, destipmatch, srcipmatch, Protocolmatch,
							destportmatch, srcportmatch, tcpackmatch, dscpmatch, markmatch, iplengthmatch, DSCPMark);
					printf("iptablescommand: %s\n", iptablescommand);
					system(iptablescommand);
				}
				else
				{
					sprintf(iptablescommand, "iptables -t mangle -D FORWARD %s %s %s %s %s %s %s %s %s -j CLASSIFY --set-class %s:0", intefacematch, destipmatch, srcipmatch, Protocolmatch,
							destportmatch, srcportmatch, tcpackmatch, dscpmatch, iplengthmatch, TrafficClass);
					printf("iptablescommand: %s\n", iptablescommand);
					system(iptablescommand);
					sprintf(iptablescommand, "iptables -t mangle -D FORWARD %s %s %s %s %s %s %s %s %s -j DSCP --set-dscp %s", intefacematch, destipmatch, srcipmatch, Protocolmatch,
							destportmatch, srcportmatch, tcpackmatch, dscpmatch, iplengthmatch, DSCPMark);
					printf("iptablescommand: %s\n", iptablescommand);
					system(iptablescommand);
				}
			}
		}
	}
}
#endif
	
int creat_queue_rules()
{
	char ShaperNumberOfEntries[32] = {0};
	char QueueNumberOfEntries[32] = {0};
	char ClassificationNumberOfEntries[32] = {0};
	char ShapingRate[32] = {0};
	char ShapingBurstSize[32] = {0};
	char InterfaceName[256] = {0};
	char TrafficClasses[256] = {0};
	char Interface[256] = {0};
	char Weight[256] = {0};
	char Precedence[256] = {0};
	char SchedulerAlgorithm[256] = {0};
	char name[256] = {0};
	char command[256] = {0};
	int i = 0;
	int j = 0;
	int classid = 1;
	int classid1 = 1;
	int wrrflag1 = 0;	
	int wrrflag2 = 0;	
	int wfqflag1 = 0;	
	int wfqflag2 = 0;	
	int setdefault = 0;
	int setdefault1 = 0;
	char value[64] = {0};
	
	memset(QueueNumberOfEntries, 0, sizeof(QueueNumberOfEntries));
	//do_uci_get("classification.Device_QoS.QueueNumberOfEntries", QueueNumberOfEntries);
	printf("QueueNumberOfEntries CCC: %s\n", QueueNumberOfEntries);
	sprintf(QueueNumberOfEntries ,"7");
	printf("QueueNumberOfEntries=%s\n",QueueNumberOfEntries );

	while(i < atoi(QueueNumberOfEntries))
	{
			j++;
                    //Device_QoS_Classification_%d
                    //Device_QoS_Queue_%d"
			sprintf(name, "queue.Device_QoS_Queue_%d", j);		
			memset(value, 0, sizeof(value));
			do_uci_get(name,value);
            printf("XXXXX name=%s, value=%s\n",name ,value );
			if(strcmp(value, "queue") == 0)
			{
				i++;
                           //Device_QoS_Classification_16
                            //classification.Device_QoS_Classification_16.SourceMas
				sprintf(name, "queue.Device_QoS_Queue_%d.TrafficClasses", j);	
				do_uci_get(name, TrafficClasses);
                          printf("XXXXX name=%s, TrafficClasses=%s\n",name ,TrafficClasses );
				sprintf(name, "queue.Device_QoS_Queue_%d.Interface", j);	
				do_uci_get(name, Interface);
				sprintf(name, "queue.Device_QoS_Queue_%d.Weight", j);	
				do_uci_get(name, Weight);
				sprintf(name, "queue.Device_QoS_Queue_%d.Precedence", j);	
				do_uci_get(name, Precedence);
				sprintf(name, "queue.Device_QoS_Queue_%d.SchedulerAlgorithm", j);	
				do_uci_get(name, SchedulerAlgorithm);

				if(strcmp(Interface, "Device.IP.Interface.1") == 0)
				{
					strcpy(InterfaceName, "br-lan");
				}
				else
				{
					strcpy(InterfaceName, "eth0");
				}

				if(strcasecmp(SchedulerAlgorithm, "SP") == 0)
				{
					sprintf(command, "tc qdisc add dev %s parent 1:1 handle 10: nssprio bands 3", InterfaceName);
					system(command);
					printf("command: %s\n", command);
					sprintf(command, "tc qdisc add dev %s parent 10:1 handle 101: nsspfifo", InterfaceName);
					system(command);
					printf("command: %s\n", command);
					sprintf(command, "tc qdisc add dev %s parent 10:2 handle 102: nsspfifo", InterfaceName);
					system(command);
					printf("command: %s\n", command);
					sprintf(command, "tc qdisc add dev %s parent 10:3 handle 103: nsspfifo set_default", InterfaceName);
					system(command);
					printf("command: %s\n", command);
				}
				else if(strcasecmp(SchedulerAlgorithm, "WRR") == 0)
				{
					if(strcmp(InterfaceName, "br-lan") == 0)
					{
						if(wrrflag1 == 0)
						{
							sprintf(command, "tc qdisc add dev %s parent 1:1 handle 2: nsswrr", InterfaceName);
							system(command);
							printf("command: %s\n", command);
							wrrflag1 = 1;
						}
						sprintf(command, "tc class add dev %s parent 2: classid 2:%d nsswrr quantum %s", InterfaceName, classid, Weight);
						system(command);
						printf("command: %s\n", command);
						if(setdefault == 0)
						{
							sprintf(command, "tc qdisc add dev %s parent 2:%d handle %d00: nsspfifo set_default", InterfaceName, classid, classid);
							system(command);
							printf("command: %s\n", command);
							setdefault = 1;
						}
						else
						{
							sprintf(command, "tc qdisc add dev %s parent 2:%d handle %d00: nsspfifo", InterfaceName, classid, classid);
							system(command);
							printf("command: %s\n", command);
						}
						classid++;
					}
					else
					{
						if(wrrflag2 == 0)
						{
							sprintf(command, "tc qdisc add dev %s parent 1:1 handle 2: nsswrr", InterfaceName);
							system(command);
							printf("command: %s\n", command);
							wrrflag2 = 1;
						}
						sprintf(command, "tc class add dev %s parent 2: classid 2:%d nsswrr quantum %s", InterfaceName, classid1, Weight);
						system(command);
						printf("command: %s\n", command);
						if(setdefault1 == 0)
						{
							sprintf(command, "tc qdisc add dev %s parent 2:%d handle %d00: nsspfifo set_default", InterfaceName, classid1, classid1);
							system(command);
							printf("command: %s\n", command);
							setdefault1 = 1;
						}
						else
						{
							sprintf(command, "tc qdisc add dev %s parent 2:%d handle %d00: nsspfifo", InterfaceName, classid1, classid1);
							system(command);
							printf("command: %s\n", command);
						}
						classid1++;
					}		
				}
				else if(strcasecmp(SchedulerAlgorithm, "WFQ") == 0)
				{
					if(strcmp(InterfaceName, "br-lan") == 0)
					{
						if(wfqflag1 == 0)
						{
							sprintf(command, "tc qdisc add dev %s parent 1:1 handle 2: nsswfq", InterfaceName);
							system(command);
							printf("command: %s\n", command);
							wfqflag1 = 1;
						}
						sprintf(command, "tc class add dev %s parent 2: classid 2:%d nsswfq quantum %s", InterfaceName, classid, Weight);
						system(command);
						printf("command: %s\n", command);
						if(setdefault == 0)
						{
							sprintf(command, "tc qdisc add dev %s parent 2:%d handle %d00: nsspfifo set_default", InterfaceName, classid, classid);
							system(command);
							printf("command: %s\n", command);
							setdefault = 1;
						}
						else
						{
							sprintf(command, "tc qdisc add dev %s parent 2:%d handle %d00: nsspfifo", InterfaceName, classid, classid);
							system(command);
							printf("command: %s\n", command);
						}
						classid++;
					}
					else
					{
						if(wfqflag2 == 0)
						{
							sprintf(command, "tc qdisc add dev %s parent 1:1 handle 2: nsswfq", InterfaceName);
							system(command);
							printf("command: %s\n", command);
							wfqflag2 = 1;
						}
						sprintf(command, "tc class add dev %s parent 2: classid 2:%d nsswfq quantum %s", InterfaceName, classid1, Weight);
						system(command);
						printf("command: %s\n", command);
						if(setdefault1 == 0)
						{
							sprintf(command, "tc qdisc add dev %s parent 2:%d handle %d00: nsspfifo set_default", InterfaceName, classid1, classid1);
							system(command);
							printf("command: %s\n", command);
							setdefault1 = 1;
						}
						else
						{
							sprintf(command, "tc qdisc add dev %s parent 2:%d handle %d00: nsspfifo", InterfaceName, classid1, classid1);
							system(command);
							printf("command: %s\n", command);
						}
						classid1++;
					}		
				}
			}
	}
	
}

int main(int argc, char *argv[]){
	if(argv[1] && (!strcmp(argv[1],S1) || !strcmp(argv[1],ALL))){
		 exec_cmd(DELS1,NULL);
	   ssidmarkdscp();
	}
	if(argv[1] && (!strcmp(argv[1],S2) || !strcmp(argv[1],ALL))){
		 exec_cmd(DELS2,NULL);
	   iptvmarkdscp();
	}
	if(argv[1] && (!strcmp(argv[1],S3) || !strcmp(argv[1],ALL))){
			exec_cmd(DELS3,NULL);
			exec_cmd("iptables -t mangle -D FORWARD -j macmark 2>/dev/null",NULL);
			exec_cmd("iptables -t mangle -X macmark 2>/dev/null",NULL);
			exec_cmd("iptables -t mangle -N macmark",NULL); 
			exec_cmd("iptables -t mangle -A FORWARD -j macmark",NULL); 
			ipmark();
	}
    #if 1
        int queue_number = 6;
        int class_number=5;
        char template_name[32]={0};
        char qos_name[32]={0};
        
        memset (template_name,0,sizeof(template_name));
        memset (qos_name,0,sizeof(qos_name));
        


        //function      :Create a new config file with the template file.
        //number        :section name; (make number to be section's name. ) 
        //template_name: template file name;                 exp :queue_template
        //qos_name: be created new qos_config name.;    exp:queue
        //note: all file should be in /etc/config/

        //for queue uci
        printf("_________________________queue_uci_config_start\n");
        sprintf(qos_name,"queue");          
        sprintf(template_name,"queue_template");
        printf("in queue uci_tmp_config_name= %s\n",template_name);
        printf("in queue created_qos_name= %s\n",qos_name);
        add_template_node(queue_number,template_name,qos_name);//for queue
        printf("======================queue_uci_config_end\n");

        
        //for classification uci
        printf("_________________________classification_uci_config_start\n");
        sprintf(template_name,"classification_template");
        sprintf(qos_name,"classification");
        printf("in classification uci_tmp_config_name= %s\n",template_name);
        printf("in classification created_qos_name= %s\n",qos_name);
        add_template_node(class_number,template_name,qos_name);//for classification
        printf("======================classification_uci_config_end\n");


        //for queue rules
        printf("_________________________classification_rules start\n");
        creat_queue_rules();
        printf("======================classification_rules end\n");

       // test_uci();
    #endif
        

return 0;


}
